import Opt from '@/components/dt/info/Opt.js'
import rankJumpApi from '@/biz/report/rankJumpReport'

class SearchOpt extends Opt {
  
  constructor(onFetch) {
    super()
    this.onFetch = onFetch
    this.build()
  }
  
  build() {
    this.createAll()
    this.opts.push(...this.all)
  }
  
  getScreen(info) {
    this.info = info
    rankJumpApi.getScreens(this.info.month).then(res => {
      this.screen.select.options = res.map((item, idx) => {
        item.key = item.rankPointsId
        item.value = item.rankPointsName
        if (idx == 0) {
          this.info.rankPointsId = item.rankPointsId
          this.onFetch()
        }
        return item
      })
    })
  }

  createAll() {
    this.screen = {
      title: '跳点方案',
      key: 'rankPointsId',
      select: {
        options: []
      }
    }
    this.all = [
      {
        title: '目标年月',
        placeholder: '全部',
        key: 'month',
        date: {
          type: 'month'
        },
        change: (res) => {
          this.info.rankPointsId = null
          this.getScreen(this.info)
        }
      },
      this.screen
    ]
  }
}

export default SearchOpt
